﻿using MediatR;
using Microsoft.EntityFrameworkCore.SqlServer.Query.Internal;
using T_Person.BaseRep.Interface;
using T_Person.Read.APi.Applaction.Command.Employment;
using T_Person.Read.APi.Dto;

namespace T_Person.Read.APi.Applaction.CommandHandlers
{
    public class EmployeeSearchBynamesHandler : IRequestHandler<EmployeeSearchBynamesCommand, PulicArrayOperator>
    {
        private readonly IEmployeeRep employeeRep;

        public EmployeeSearchBynamesHandler(IEmployeeRep employeeRep)
        {
            this.employeeRep = employeeRep;
        }

        public async Task<PulicArrayOperator> Handle(EmployeeSearchBynamesCommand request, CancellationToken cancellationToken)
        {
            var lists = await employeeRep.GetAloneByresult(x => x.Ename == request.name);
            var list = new PulicArrayOperator
            {
                id = lists.Eid,
               phone=lists.Ephone,
               dname=lists.DepartId,
            };
            return await Task.FromResult(list);
        }
    }
}
